package common.tool.box.common.enums;

import org.springframework.lang.Nullable;

import java.util.HashMap;
import java.util.Map;

/**
 * 用户状态
 * 
 * @author ruoyi
 */
public enum JsonOperationType
{
    MOCK(0, "随机生成JSON"),
    STRING_TO_JSON(1, "字符转换Json"),
    JSON_TO_STRING(2, "Json转字符"),
    JSON_ESCAPE(3, "Json转义"),
    JSON_UNESCAPE(4, "Json反转义"),
    JSON_TO_Java(5, "Json转Java");

    private static final Map<Integer, JsonOperationType> mappings = new HashMap<>(16);

    static
    {
        for (JsonOperationType jsonOperationType : values())
        {
            mappings.put(jsonOperationType.getType(), jsonOperationType);
        }
    }

    private final Integer type;
    private final String name;

    @Nullable
    public static JsonOperationType resolve(@Nullable Integer type)
    {
        return (type != null ? mappings.get(type) : null);
    }

    public boolean matches(int type)
    {
        return (this == resolve(type));
    }

    JsonOperationType(Integer type, String name)
    {
        this.type = type;
        this.name = name;
    }

    public Integer getType() {
        return type;
    }

    public String getName() {
        return name;
    }
}
